package view.elements{
	/**
	 * @author Alejandro
	 */
	
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.display.Shape;
	import flash.events.MouseEvent;
	import view.components.button.CompleteButton;
	import view.concret.MoveBall;
	import view.elements.ConcretApplication;
	import view.components.text.CompleteText;
	
	import flash.display.Loader;
	import flash.net.URLRequest;
	
	public class AppContainerTemplate01 extends Sprite {
		
		private var play:Boolean;
		private var application:ConcretApplication;
		private var playButton:CompleteButton;
		private var stopButton:CompleteButton;
		
		public function AppContainerTemplate01(){
			init();
		}
		
		private function init(e:Event = null):void{
			play = false;
			loadBackground();
			createButtons();
			application = new MoveBall();
			addChild(application);
		}
		
		
		private function loadBackground():void{
			var url:String = "media/background_fix.jpg";
			var loader:Loader = new Loader();
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadImage);
			loader.load( new URLRequest(url));
		}
		
		private function loadImage(e:Event):void {
			trace("Cargada: " + e);
			var image:DisplayObject = e.target.content;
			addChild(image);
			setChildIndex(image, 0);
			
		}
		
		private function createButtons():void{
			createPlayButton();
			createStopButton();
			var style:Object = {
				x: 100,
				y: 400,
				backgroundColor: "AA0099",
				text:"hola",
				height: 50,
				width: 100,
				size: 44
				};
			var text:CompleteText = new CompleteText(style);
		    addChild(text);
		}
		
		
		private function createPlayButton():void{
			var style:Object = {
				upState: {
					backgroundColor: "111111",
					fontColor: "BBBBBB"
				},
				overState: {
					backgroundColor: "555555",
					fontColor: "FFFFFF"
				},
				downState: {
					backgroundColor: "AAAAAA",
					fontColor: "333333"
				},
				width: 100,
				height: 20,
				x: 0,
				y: 550,
				text: "Play"
				};
			playButton = new CompleteButton(style);			
			playButton.addEventListener(MouseEvent.CLICK, playApplication);			
			addChild(playButton);
		}
		
		private function createStopButton():void{
			var style:Object = {
				upState: {
					backgroundColor: "555555",
					fontColor: "BBBBBB"
				},
				overState: {
					backgroundColor: "999999",
					fontColor: "FFFFFF"
				},
				downState: {
					backgroundColor: "AAAAAA",
					fontColor: "333333"
				},
				text: "Stop",
				width: 100,
				height: 40,
				x: 100,
				y: 550,
				visible: false
				};
			stopButton = new CompleteButton(style);
			stopButton.addEventListener(MouseEvent.CLICK, stopApplication);
			addChild(stopButton);
		}
		
		private function playApplication(event:MouseEvent):void {
			this.application.playApplication();
			stopButton.visible = true;
			playButton.visible = false;
		}
		
		private function stopApplication(event:MouseEvent):void {
			this.application.stopApplication();
			stopButton.visible = false;
			playButton.visible = true;
		}
	}
}